package com.encryption.rpc;

import java.util.List;

import com.encryption.logic.ManageActionConstant;
import com.encryption.logic.ManageActionLogHelper;
import com.encryption.model.Department;
import com.encryption.service.DepartmentService;
import com.encryption.service.impl.DepartmentServiceImpl;

public class DepartmentFacade {
	private DepartmentService service = DepartmentServiceImpl.getDepartmentServiceImpl();
	
	public List<Department> getAll(){
		return service.getAll();
	}
	
	public int addDepart(Department depart){
		service.addDepartment(depart);
		
		ManageActionLogHelper.addLog(ManageActionConstant.ACTION_ADD_DEPT, depart.getName());
		return depart.getId();
	}
	
	public void editDepart(Department depart){
		Department cacheDepart = service.getDepartmentById(depart.getId() + "");
		ManageActionLogHelper.addLog(ManageActionConstant.ACTION_EDIT_DEPT, "将" + cacheDepart.getName() + "更名为" + depart.getName());
		
		cacheDepart.setName(depart.getName());
		service.updateDepartment(cacheDepart);
	}
	
	public void deleteDepart(int id){
		service.deleteDepartment(id + "");
	}
}
